package com.ht.controller;

import cn.hutool.json.JSONUtil;
import com.ht.data.Result;
import com.ht.dto.TbDiagnoseOrder;
import com.ht.dto.User;
import com.ht.service.ITbDiagnoseOrderService;
import com.ht.util.JwtUtil;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api("关于用户的订单信息")//Swagger2的注解
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private ITbDiagnoseOrderService orderService;


    @GetMapping("/getOrderStatus/{status}")
    //value为这个方法干什么用的
    @ApiOperation(value = "根据状态查询订单")
    //name是传的参是谁，value的意思是传的是什么，required是否必填，paramType传参的方式
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "用户token",required = true,paramType = "header"),
            @ApiImplicitParam(name = "status",value = "订单状态：1、待支付；2、进行中；3、已完成；4、已取消",required = true,paramType = "path")
    })
    public Result getOrderStatus(@RequestHeader("AuthToken")String token, @PathVariable("status")String status){
        Claims claims = new JwtUtil().parseJwt(token);
        User user = JSONUtil.toBean(claims.getSubject(), User.class);
        List<TbDiagnoseOrder> list = orderService.getOrderStatus(user.getId(),status);
        return Result.OK().setData(list);
    }

    @PostMapping("/getInvoiceStatus/{invoiceStatus}")
    //value为这个方法干什么用的
    @ApiOperation(value = "查询发票状态")
    //name是传的参是谁，value的意思是传的是什么，required是否必填，paramType传参的方式
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "用户token",required = true,paramType = "header"),
            @ApiImplicitParam(name = "invoiceStatus",value = "发票状态 0/1  未开/已开;",required = true,paramType = "path")
    })
    public Result getInvoiceStatus(@RequestHeader("AuthToken")String token, @PathVariable("invoiceStatus")String invoiceStatus){
        Claims claims = new JwtUtil().parseJwt(token);
        User user = JSONUtil.toBean(claims.getSubject(), User.class);
        List<TbDiagnoseOrder> list = orderService.getInvoiceStatus(user.getId(),invoiceStatus);
        return Result.OK().setData(list);
    }

}
